#pragma once 
#include<iostream>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<unistd.h>
#include<cstdlib>
#include<cstring>
#include"Log.hpp"

#define LONG 5

class sock_server{
  public:
    static int Sock()
    {
      int lisent_sock=socket(AF_INET,SOCK_STREAM,0);
      if(lisent_sock<0){
        //std::cerr<<"socket error"<<std::endl;
        LOG(FATAL,"sock erroe!");
        exit(1);
      }
      int opt=1;
      setsockopt(lisent_sock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));

      LOG(INFO,"sock success!");
      return lisent_sock;
    }
    static void Bind(int sock,int port)
    {
      struct sockaddr_in crpp;
      memset(&crpp,0,sizeof(crpp));
      crpp.sin_family=AF_INET;
      crpp.sin_port=htons(port);
      crpp.sin_addr.s_addr=INADDR_ANY;
      if(bind(sock,(struct sockaddr*)&crpp,sizeof(crpp))<0){
        LOG(FATAL,"bind error!");
        exit(2);
      }
      LOG(INFO,"bind success");
    }
    static void Linst(int sock)
    {
      if(listen(sock,LONG)<0){
        LOG(FATAL,"listen error!");
        exit(3);
      }
      LOG(INFO,"listen success");
    }
};
